import React from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'

const RouteView = (props) => {
    const { routes } = props
    return <Switch>
        {
            routes.map((item, index) => item.path ?
                <Route path={item.path} key={index}
                    render={(History) => {
                        return <item.component routes={item.children ? item.children : []} {...History}>
                            <RouteView routes={item.children ? item.children : []}></RouteView>
                        </item.component>
                    }}
                ></Route>
                : <Redirect key={index} {...item} exact></Redirect>)
        }
    </Switch>
}
export default RouteView
